<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreatePackageProductMappingsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('package_product_mappings', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('packageId')->default(0)->comment('套餐id');
            $table->unsignedInteger('menuId')->default(0)->comment('菜单id');
            $table->unsignedBigInteger('productId')->default(0)->comment('套餐关联商品id');
            $table->unsignedInteger('num')->default(0)->comment('套餐商品数量');
            $table->string('productName')->default('')->comment('套餐商品名称');
            $table->unsignedInteger('price')->default(0)->comment('套餐商品价格');
            $table->string('unit', 10)->default(0)->comment('套餐商品规格');
            $table->string('imageUrl', 50)->default(0)->comment('套餐商品图片');
            $table->unsignedInteger('categoryId')->default(0)->comment('套餐商品分类ID');
            $table->index('packageId', 'idx_package_id');
            $table->index('menuId', 'idx_menu_id');

            $table->collation = 'utf8mb4_general_ci';
        });

        $prefix = config('other.DB_PREFIX', '');
        \Illuminate\Support\Facades\DB::statement("ALTER TABLE `{$prefix}package_product_mappings` COMMENT = '套餐商品关联表'"); //表注释
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('package_product_mappings');
    }
}
